package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class PopUpWindow extends JFrame {
	
	private MasterView m;
	private JPanel body; 
	
	public PopUpWindow(MasterView m, PopUps type){
		this.m = m;
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		switch(type){
		case ALERT:
			this.setLayout(new BorderLayout());
			setUpAlertWindow();
			break;
		case PAUSE:
			this.setLayout(new BorderLayout());
			setUpPauseWindow();
			break;
			
		}
	}
	
	private void setUpAlertWindow(){
		
		this.setTitle("Tanks");
		this.setLocationRelativeTo(m);

		JPanel bodyPanel = new JPanel(new BorderLayout(5,5));
		bodyPanel.setPreferredSize(new Dimension(250, 250));

		JLabel header = new JLabel("Corrupted File");
		bodyPanel.add(header);
		
		GameButton ok = new GameButton(new ImageIcon("images/goBack.png"), 
				new ImageIcon("images/goBackS.png"));
		bodyPanel.add(ok, BorderLayout.SOUTH);
		
		this.add(bodyPanel);
		this.pack();
		this.setSize(new Dimension(300, 100));
		this.setVisible(true);
		this.requestFocus();
	}
	
	private void setUpPauseWindow(){

		body = new JPanel(new GridLayout(3,0));
		
		GameButton save = new GameButton(new ImageIcon("images/buttons/save.png"), 
				new ImageIcon("images/buttons/saveS.png"));
		save.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		
		GameButton menu = new GameButton(new ImageIcon("images/buttons/mainMenu.png"), 
				new ImageIcon("images/buttons/mainMenuS.png"));
		menu.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				m.changeView(Views.MENU, null);
			}
		});
		
		GameButton exit = new GameButton(new ImageIcon("images/buttons/exit.png"), 
				new ImageIcon("images/buttons/exitS.png"));
		exit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		
		body.add(save);
		body.add(menu);
		body.add(exit);
		this.add(body);

//		this.setBackground(new Color(0.2f, 0.2f, 0.2f, 0.2f));
		this.setSize(new Dimension(300, 150));
		this.setLocationRelativeTo(m);
		this.setVisible(true);
		this.requestFocus();	
	}
}
